/**
 * @Title:CacheCodeAction.java
 * CopyRight(c)2010-DMX
 */
package com.dmx.fw.web.struts2.action.system;

import java.io.IOException;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.dmx.fw.bean.mapping.pojo.CacheCode;
import com.dmx.fw.web.struts2.action.BaseAction;
import com.dmx.fw.service.interfaces.CacheCodeService;
/**
 * @Description: CacheCode Manager
 * @author Ma Qiang
 * @date 2010-4-29
 * @version V1.0
 */
public class CacheCodeAction extends BaseAction {
	final private static Log log = LogFactory.getLog(CacheCodeAction.class);
	/**
	 * @Fields id:Cache Code ID
	 */
	private String id;
	/**
	 * @Fields cacheCodeService : CacheCodeService
	 */
	private CacheCodeService cacheCodeService;
	/**
	 * @Fields cacheCode : CacheCode
	 */
	private CacheCode cacheCode;
	/**
	 * @Fields oldCode : 修改时的旧code
	 */
	private String oldCode;

	public String execute() throws Exception {
		return super.execute();
	}
	/**
	 * @Description: 进入添加输入界面
	 * @param 
	 * @return String
	 */
	public String doAddInput() {
		return "addInput";
	}
	/**
	 * @Description: 执行添加提交操作
	 * @param 
	 * @return String
	 */
	public String doAddSubmit() throws Exception {
		 if (cacheCodeService.checkCodeUnique(cacheCode)) {
			 this.setAjaxJsonMsgResult(getText("cacheCode.validate.codeDuplicate"),null);
		 } else {
			 cacheCodeService.saveObject(cacheCode);
			 this.setSuccessinfo(this.getText("info.addSuccess"));
			 this.setAjaxJsonUrlResult("system/cacheCodeSearchAction.action?act=query&busiId=searchCacheCode");
		 }
		 return null;
	}
	/**
	 * @Description: 进入修改输入界面
	 * @param 
	 * @return String
	 */
	public String doEditInput() {
		cacheCode = cacheCodeService.getOneCacheCode(Long.valueOf(id));
		return "editInput";
	}
	/**
	 * @Description: 执行修改提交界面
	 * @param 
	 * @return String
	 */
	public String doEditSubmit() throws IOException {
		if (!oldCode.equals(cacheCode.getCode())&&cacheCodeService.checkCodeUnique(cacheCode)) {
			this.setAjaxJsonMsgResult(getText("cacheCode.validate.codeDuplicate"),null);
		} else {
			cacheCodeService.updateObject(cacheCode);
			this.setSuccessinfo(this.getText("info.modifySuccess"));
			this.setAjaxJsonUrlResult("system/cacheCodeSearchAction.action?act=query&busiId=searchCacheCode");
		}
		return null;
	}
	/**
	 * @Description: 执行删除操作
	 * @param 
	 * @return String
	 */
	public String doDelete() throws IOException {
		cacheCode = new CacheCode();
		cacheCode.setCachCodeId(new Long(id));
		cacheCodeService.removeObject(cacheCode);
		this.setSuccessinfo(this.getText("info.deleteSuccess"));
		this.setAjaxJsonUrlResult("system/cacheCodeSearchAction.action?act=query&busiId=searchCacheCode");
		return null;
	}
	/**
	 * @Description: 执行查看动作
	 * @param 
	 * @return String
	 */
	public String doView() {
		cacheCode = cacheCodeService.getOneCacheCode(Long.valueOf(id));
		return "view";
	}
	/**
	 * @Description: 获取“是、否”，用于查看时显示，页面标签中只写“isCacheText”
	 * @param 
	 * @return String
	 */
	public String getIsCacheText() {
		return cacheCodeService.getIsCacheTextByCode(cacheCode.getCached());
	}
	/**
	 * @Description: 获取“是、否”下拉框的内容，页面标签中只写“listYesNo”
	 * @param 
	 * @return List
	 */
	public List getListYesNo() {
		return cacheCodeService.getIsCacheList();
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public CacheCodeService getCacheCodeService() {
		return cacheCodeService;
	}

	public void setCacheCodeService(CacheCodeService cacheCodeService) {
		this.cacheCodeService = cacheCodeService;
	}

	public CacheCode getCacheCode() {
		return cacheCode;
	}

	public void setCacheCode(CacheCode cacheCode) {
		this.cacheCode = cacheCode;
	}

	public String getOldCode() {
		return oldCode;
	}

	public void setOldCode(String oldCode) {
		this.oldCode = oldCode;
	}
}
